<?php
class Application_Model_Search_Index_Publication extends Application_Model_Search_Index_Abstract {
	
	/**
	 * Returns the directory where the index is stored.
	 *
	 * @author b.wenneker <b.wenneker@gmail.com>, 2010
	 * @return string Directory where the index is stored.
	 */
	public static function getIndexDirectory(){
		
		return parent::getIndexDirectory() .'/publications';
	}
	
	/**
	 * updateDocument() - Update the index with the index data. Updating is done by removing any
	 * duplicates and then reinsert a new document.
	 *
	 * @author b.wenneker <b.wenneker@gmail.com>, 2010
	 * @param array $publication Data to build the document to update from.
	 */
	public function updateDocument($publication){
		 
		$document 			= $this->getNewDocumentInstance($publication);
		$index 				= $this->getIndex();
		
		$document->addField(Zend_Search_Lucene_Field::Text('title', $publication['title']));
		
		// Remove duplicates and reinsert updated document, this is how updating the index works.
		$this->_deleteDuplicates($publication);
		$index->addDocument($document);
	}
	
	/**
	 * Returns a value that is used to identify the document containing the
	 * indexdata.
	 *
	 * @author b.wenneker <b.wenneker@gmail.com>, 2010
	 * @param array $publication Data to build the document to update from.
	 * @return string Identifier field value.
	 */
	public function getIdentifierFieldValue($publication){
		
		return 'publication.'.$publication['title'];
	}
}